package com.weiyi.servlet02;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
 * 
 * @description 打印报文正文信息
 * @author 惟一
 * @date 2020年6月26日下午5:57:56
 */
@WebServlet("/body.view")
public class BodyDemo extends HttpServlet{

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		String body = readBody(req);
		PrintWriter out = resp.getWriter();
		out.println("<html>");
		out.println("<head>");
		out.println("<title>BodyDemo</title>");
		out.println("</head>");
		out.println("<body>");
		out.println(body);
		out.println("</body>");
		out.println("</html>");
		
		out.close();
	}
	
	private String readBody(HttpServletRequest req) throws IOException {
		String requestBody = "";
		String input = null;
		BufferedReader reader = req.getReader();
		while( (input = reader.readLine()) != null) {
			requestBody = requestBody + input +"</br>";
		}
		return requestBody;
	}
}
